package org.ceteca.explica.client;

import org.ceteca.javaglade.toolkit.swt.StatusBar;
import org.eclipse.swt.widgets.ProgressBar;

public class UpdateInitProgressBarOperation implements Runnable {
	private ProgressBar progressBar;
	private int progressInc;
	private StatusBar statusBar;
	private String statusText;
	
	public UpdateInitProgressBarOperation(ProgressBar progressBar, StatusBar statusBar, String statusText) {
		this.progressBar = progressBar;
		this.progressInc = -1;
		this.statusBar = statusBar;
		this.statusText = statusText;
	}
	
	public UpdateInitProgressBarOperation(ProgressBar progressBar, int progressInc, StatusBar statusBar, String statusText) {
		this.progressBar = progressBar;
		this.progressInc = progressInc;
		this.statusBar = statusBar;
		this.statusText = statusText;
	}
	
	public void run() {
		if (progressBar.isDisposed()) return;
        
        // Increment the progress bar
        progressBar.setSelection(progressBar.getSelection() + (this.progressInc < 0?1:this.progressInc));
        
        // Set the status bar text
        statusBar.updateStatus(statusText);
        
//        progressBar.getParent().layout(true);
	}
}